<?php


namespace app\crontab\controller\once;


use custom\Redis;
use think\console\Command;
use think\console\Input;
use think\console\Output;

/**
 * 替换小区名称特殊符号
 * Class ReplaceHouseVillageTitle
 * @package app\crontab\controller
 */
class ReplaceHouseVillageTitle extends Command {
    protected function configure() {
        $this->setName('ReplaceHouseVillageTitle');
    }

    protected function execute(Input $input, Output $output) {
        echo "start\n";
        $data = db('house_village')
            ->where('name', 'regexp', '\\(|\\（|\\）|\\)')
            ->field('id,name')
            ->select();
        $int = 0;
        foreach ($data as $index => $datum) {
            $name = replaceSpecialChar($datum['name']);
            if (db('house_village')
                    ->where('id', $datum['id'])
                    ->update(['name' => $name]) !== false) $int++;
        }
        echo "total->" . count($data) . "\n";
        echo "suc->" . $int . "\n";
        echo "end\n";
    }

}